#include <algorithm>
#include <cstdio>

const int N = 1000005;
int n;
int c[N], f[N];

inline bool cmp(int x, int y) { return x > y; }

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("P2964 A Coin Game S.in", "r", stdin);
  freopen("P2964 A Coin Game S.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
  std::sort(c + 1, c + n + 1, cmp);
  f[n] = 0;
  for (int i = n; i; --i) {
    f[i] = f[i + 1];
    f[i] = std::max(f[i], c[i] - f[i + 1]);
  }
  printf("%d", f[1]);
  return 0;
}